/*
 * Sapphire
 *
 * Copyright (C) 2018 Florrie Haero
 * Copyright (C) 2018 Alyssa Rosenzweig
 * Copyright (C) 2018 eq
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02111-1301  USA
 *
 */

body, html {
    width: 100%;
    height: 100%;
    padding: 0;
    margin: 0;

    font-family: Cantarell, Lato, -apple-system, BlinkMacSystemFont, sapphire-emoji, sans-serif;

    /* We need to establish a font-size globally so we can set min-height correctly. TODO: Do we want a preprocessor of some kind? */
    font-size: 1em;

    background-color: var(--bg-color);
    color: var(--text-color);

    /* Don't break the layout */
    word-break: break-word;
}

/* Arc Dark */
input, button, textarea {
    background-color: var(--button-bg-color) !important;
    color: var(--button-text-color) !important;
    padding: 0.5em;

    /* Nice rounded corners */
    border-radius: 0.3em;
    border-style: none;

    /* Fix the font -- I don't know why this has to be explicit, but hey! */
    font-family: Cantarell, Lato, -apple-system, BlinkMacSystemFont, sapphire-emoji, sans-serif;
}

button, input[type=button], input[type=submit] {
    cursor: pointer;
}

::-webkit-scrollbar {
    background-color: var(--scroll-color);
}

::-webkit-scrollbar-thumb {
    background-color: var(--scroll-thumb-color);
    border-radius: 1em;
}

a, a:visited {
    color: var(--link-color);
}

.icon {
    height: 0.75em;
    width: 0.75em;
}

#app {
    position: absolute;

    display: flex;
    flex-direction: row;

    width: 100%;
    height: 100%;
}

#app > .pane {
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
}

#buddy-list-pane, #chat-user-list-pane {
    min-width: 58px;
    max-width: 250px;

    background: var(--bg-accent-color);

    overflow-x: hidden;
    padding: 2px 0;
    box-sizing: border-box;
}

#chat-pane {
    display: flex;
    flex-direction: column;
    min-width: 300px;

    padding: 4px 20px 4px 20px;
    box-sizing: border-box;
}

#app:not(.chat) #chat-user-list-pane {
    display: none;
}

.pane-scroller {
    flex-grow: 1;
    overflow-y: scroll;
}

.pane-footer {
    border-top: 1px solid var(--border-color);
    font-size: 1.5em;
    padding: 5px;

    display: flex;
    flex-direction: row;
    justify-content: space-between;

    /* Don't squish */
    min-height: 1em;
    align-items: center;
}

#buddy-list-pane button {
    width: 100%;
}

#add-buddy {
    color: var(--text-color) !important;
}

#change-avatar {
    color: var(--text-color) !important;
}

.user, #chat-list .chat {
    /* You: "Seriously, Florrie? You need display: flex for THIS?!" */
    display: flex;
    flex-direction: row;
    align-items: center;

    color: inherit;
    text-decoration: none;

    height: 40px;
    padding: 0 8px;
    box-sizing: border-box;
}

.user:focus:not(.selected), #chat-list .chat:focus:not(.selected) {
    background-color: var(--chat-switch-color);
    filter: brightness(1.4);
}

.user.selected, #chat-list .chat.selected {
    background-color: var(--accent-button-bg-color);
    color: var(--accent-button-text-color);
}

.user.selected .user-name, #chat-list .chat.selected .chat-name {
    color: var(--select-text-color);
}

/* For unselected, unread bolds, typing greens. Unread implies not selected;
 * typing may or may not be selected. Unread but not typing is blued, as per
 * Pidgin conventions */

.user.unread {
    font-weight: 800;
}

.user.typing:not(.selected) {
    color: var(--buddy-typing-color);
}

.user.unread:not(.typing) .user-name {
    color: var(--buddy-unread-color);
}

.user-avatar {
    /* min so that it works with flex - otherwise it gets shrunk to the size
     * of the img, which makes the user's name appear offset to be closer to
     * the image. */
    min-width: 30px;
    height: 30px;
}

.inner-avatar {
    width: 100%;
    height: auto;
}

.user-avatar .inner-avatar {
    max-width: 30px;
    max-height: 30px;

    border-radius: 2px;
}

.user-name, .chat-name {
    flex-grow: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    margin-left: 8px;
    margin-right: 4px;
    white-space: nowrap;
}

/* Needs to be overrided explicitly due to a:visited nonsense */
.user:not([data-status-id=offline]) {
    color: var(--text-color) !important;
}

.user[data-status-id=offline] {
    color: var(--text-disabled-color);
}

#chat-list .chat {
    color: var(--text-color);
}

/* Status colors themselves, besdies the grey already specified */
.status-online, .status-available {
    color: var(--status-online-color);
}

.status-away {
    color: var(--status-away-color);
}

.status-dnd {
    color: var(--status-dnd-color);
}

.user[data-status-id=offline] .user-avatar .inner-avatar {
    filter: saturate(0);
    opacity: 0.8;
}

.group-heading {
    border-bottom: 1px solid var(--border-color);
    padding-left: 4px;
    font-weight: 800;
    margin-top: 4px;
}

#message-list-container {
    padding: 10px;
    flex-grow: 1;
    overflow-x: hidden;
    overflow-y: scroll;
}

/* Focusing on the message list container is just used to redirect focus to
 * the input text field, since logically these are the same. Accordingly,
 * disable the outline on both
 */

#message-list-container:focus, input[data-id=input]:focus {
    outline: none;
}

#chat-input-area {
    padding: 10px;
    border-top: 1px solid var(--border-color);
}

#chat-form {
    display: flex;
    flex-direction: row;

    /* Corresponds to font size + padding */
    min-height: 1.5em;
}

#chat-form textarea {
    width: 100%;
    min-width: 0;
    flex-grow: 1;
    resize: none;
    margin-right: 6px;
    box-sizing: content-box;
}

input[data-id=input] {
    flex-grow: 1;
    margin-right: 5px;
}

#typing-indicator {
    margin-top: 4px;
    font-size: 0.7em;
    height: 0.7em;
    opacity: 0.8;
}

.message-group {
    padding: 10px 0;
}

.message-group:not(:first-child) {
    border-top: 1px solid var(--message-border-color);
}

.message-group {
    display: flex;
    flex-direction: row;
}

.message-group-avatar .inner-avatar {
    width: 40px;
    height: 40px;
    margin-right: 12px;
    border-radius: 3px;
}

.message {
    margin-bottom: 2px;
}

.message-author {
    font-weight: 800;
}

.message-content {
    white-space: pre-wrap;
}

/* DO NOT CHANGE this max-width value without updating the MOBILE_WIDTH JS constant! */
@media only screen and (max-width: 600px) {
    #app.show-chat-area > #buddy-list-pane {
        display: none;
    }

    #app.show-buddy-list > #chat-pane {
        display: none;
    }

    #app.show-buddy-list > #chat-user-list-pane {
        display: none;
    }

    #buddy-list-pane {
        max-width: 100%;
    }

    #room-back {
        display: flex !important;
    }
}

#app:not(.show-chat-user-list) > #chat-user-list-pane {
    display: none;
}

#room-info {
    display: flex;
    flex-direction: row;
    min-width: 0;
    flex-shrink: 0;

    padding-bottom: 3px;
    border-bottom: 1px solid var(--border-color);
}

#room-info-content {
    flex-grow: 1;
    min-width: 0;
    display: flex;
    flex-direction: row;
}

.room-name-topic-container {
    display: flex;
    flex-direction: column;
}

#room-info-content .room-name {
    font-size: 1.5em;
    font-weight: bold;
}

#room-info-content .room-name, #room-info-content .room-topic {
    white-space: nowrap;
    overflow-x: hidden;
    text-overflow: ellipsis;
}

.room-avatar {
    height: 100%;
    width: 40px;
    margin-right: 10px;

    display: flex;
    align-items: center;
}

.room-button {
    display: flex;
    flex-shrink: 0;
    font-size: 1.5em;
    align-items: center;
    justify-content: center;
    padding: 0 10px;

    color: var(--button-text-color) !important;
    text-decoration: none;
}

.room-button > img {
    height: 1.75em;
    width: auto;
    flex-shrink: 0;
}

#room-back {
    display: none;
}

#app:not(.chat) #toggle-chat-user-list {
    display: none;
}

/* Modals */

#modal-screen {
    background-color: var(--modal-screen-bg-color);
}

#modal-screen:not(.visible) { display: none; }

/* Login screen is not a modal, but follows the same "center the content" rules. */
#modal-screen, #login-screen {
    position: absolute;
    width: 100%;
    height: 100%;

    /* Yes, more flex. Seriously, this is the one case where it is MEANT to be useful. */
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
}

#modal-content {
    padding: 20px;
    background-color: var(--modal-content-bg-color);
    color: var(--modal-text-color);
    border-radius: 5px;
    box-shadow: 0 0 8px black;
    max-width: 600px;
    margin: 10px;
}

#modal-content .actions {
    width: 100%;
    display: flex;
    flex-direction: row;
}

#modal-content .actions input {
    flex-grow: 1;
    margin: 5px;
}

#modal-content input[type=submit] {
    background-color: var(--accent-button-bg-color) !important;
    color: var(--accent-button-text-color);
}

/* Login screen! */

#login-screen {
    background-color: var(--bg-color);
}

#login-screen:not(.visible),
#login-status:not(.visible),
#login-form:not(.visible) { display: none; }

#login-content, #login-form {
    text-align: center;
}

#login-content h1, #modal-content h1 {
    margin-top: 0;
    margin-bottom: 0.4em;
}

#login-content label, #modal-content label {
    display: block;
    margin-bottom: 0.8em;
}

#login-content input[type=submit] {
    width: 100%;
    background-color: var(--accent-button-bg-color) !important;
    color: var(--accent-button-text-color) !important;
}
